#include "process.h"
#include "fs.h" 
#include "fcntl.h"
uint32_t get_file_mode(uint32_t mode){
	return mode & ~get_current_process()->mask;
}

uint16_t to_fcntl(uint8_t perm){
	uint16_t result = 0;
	if (perm & 4)
		result |= FREAD;
	if (perm & 2)
		result |= FWRITE;
	result |= ~3;
	return result;
}

uint8_t get_permissions(vfs_node_t *node){
	process_info_t *p = get_current_process();
	uint8_t perms = 0;
	uint8_t mask = 0;
	uint8_t shift = 0;
	if (p->uid == node->uid && p->gid == node->gid)
		shift = 6;
	else if (p->gid == node->gid) 
		shift = 3;
	perms = (uint8_t)((node->mask >> shift) & 7);
	mask = (uint8_t)((p->mask >> shift) & 7);
	return perms & ~mask;
}